<template>
    <div>
        <!-- 条件查询 -->
         <el-row>
          <el-col :span="24"><div class="grid-content bg-purple-dark">
              <el-form :inline="true" :model="searchData" clearable class="demo-form-inline">
                <el-form-item label="班级名称">
                  <el-input v-model="searchData.className" clearable></el-input>
                </el-form-item>
                  <el-button type="primary" @click="searchAdmin">查询</el-button>
                  
                <!-- </el-form-item> -->
              </el-form>
              </div></el-col>
        </el-row>

        <!-- 表格展示 -->
        <el-row>
          <el-col :span="24"><div class="grid-content bg-purple-dark">
              <el-table :data="findAdminData" border height="550" >
                <el-table-column prop="id" label="Id"></el-table-column>
                <el-table-column prop="className" label="班级名称"></el-table-column>
                <el-table-column prop="classWord" label="班级口令"  width="350"></el-table-column>></el-table-column>
                <el-table-column prop="num" label="班级人数"></el-table-column>           
                <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
      
                <el-table-column label="操作" width="260">
                    <template slot-scope="scope">

                        <el-button size="small" @click="getAdmin(scope.row)" plain>编辑</el-button>
                        <el-button size="small" type="danger" @click="delAdmin(scope.row)" plain >删除</el-button>
                  
                    </template>
                </el-table-column>
              </el-table>

            <!-- 分页 -->
            <div class="block">
                <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNum"
                :page-sizes="[2, 4, 6, 8]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total" style="float:right">
                </el-pagination>
            </div>


              </div></el-col>
        </el-row>

    </div>
</template>

<script>
import axios from 'axios';

export default {
    data(){
        return{
            findAdminData:[],
            pageNum:1,
            pageSize:2,
            total:null,
            searchData:{
                "className":""
            },
        }
    },
    created(){
        this.initTable()
    },
    methods:{

        //删除
         delAdmin(row){
            axios.delete("/api/class/deleteClassById?id="+row.id).then(res=>{
                this.$message({
                  message: res.data.message,
                  type: 'success'
                });
                this.initTable();
            })
        },

        //条件查询
        searchAdmin(){
            this.initTable();
        },
        //查询
        initTable(){
            axios.post("/api/class/findTbClassPaginationList?pageNum=" + this.pageNum + "&pageSize=" +this.pageSize,this.searchData)
                .then(res=>{
                    this.findAdminData = res.data.data.items
                    this.total = res.data.data.totalElements
                })
        },
        //分页
        handleSizeChange(val) {
          this.pageSize = val;
          console.log(`每页 ${val} 条`);
          this.initTable();
        },
        handleCurrentChange(val) {
          this.pageNum = val;
          console.log(`当前页: ${val}`);
           this.initTable()
        },

        getAdmin(row){
          //跳页面并带id
          sessionStorage.setItem("id",row.id);
            this.$router.push("/create")
        }
    }
}
</script>

<style scoped>



</style>